(function (vc) {

    vc.extends({
        data: {
            addAShopMenuInfo: {
                hktId: '',
                hktName: '',
                hktIcon: '',
                hktDesc: '',
                label: '',
                seq: '',
                url: '',
                skipType: 'S',
                isShow: '',
                typeCd: '2002',
                shopId: '',
                shops:[],
            },
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('addAShopMenu', 'openAddAShopMenuModal', function () {
                $that._listAShopMenuShops();
                $('#addAShopMenuModel').modal('show');
            });
            vc.on("addAShopMenu", "notifyUploadCoverImage", function (_param) {
                if (_param) {
                    $that.addAShopMenuInfo.hktIcon = _param[0]
                } else {
                    $that.addAShopMenuInfo.hktIcon = '';
                }
            });
        },
        methods: {
            addAShopMenuValidate() {
                return vc.validate.validate({
                    addAShopMenuInfo: $that.addAShopMenuInfo
                }, {
                    'addAShopMenuInfo.hktName': [{
                        limit: "required",
                        param: "",
                        errInfo: "类别名称不能为空"
                    },
                    {
                        limit: "maxLength",
                        param: "30",
                        errInfo: "类别名称名称太长"
                    },
                    ],
                    'addAShopMenuInfo.hktIcon': [{
                        limit: "required",
                        param: "",
                        errInfo: "小图标不能为空"
                    }],
                    'addAShopMenuInfo.hktDesc': [{
                        limit: "maxLength",
                        param: "50",
                        errInfo: "服务描述太长"
                    },],
                    'addAShopMenuInfo.label': [{
                        limit: "maxLength",
                        param: "15",
                        errInfo: "标签描述太长"
                    },],
                    'addAShopMenuInfo.seq': [{
                        limit: "required",
                        param: "",
                        errInfo: "排序不能为空"
                    },
                    {
                        limit: "num",
                        param: "",
                        errInfo: "排序不是有效数字"
                    },
                    ],
                    'addAShopMenuInfo.isShow': [{
                        limit: "required",
                        param: "",
                        errInfo: "是否显示不能为空"
                    },
                    {
                        limit: "maxLength",
                        param: "2",
                        errInfo: "是否显示格式错误"
                    },
                    ]
                });
            },
            saveAddAShopMenuInfo: function () {
                if (!$that.addAShopMenuValidate()) {
                    vc.toast(vc.validate.errInfo);

                    return;
                }
                $that.addAShopMenuInfo.url = '/pages/cate/cate?shopId=' + $that.addAShopMenuInfo.shopId;
                //不提交数据将数据 回调给侦听处理
                vc.http.apiPost(
                    '/productMenu.saveProductMenu',
                    JSON.stringify($that.addAShopMenuInfo), {
                    emulateJSON: true
                },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#addAShopMenuModel').modal('hide');
                            $that.clearAddAShopMenuInfo();
                            vc.emit('housekeepingType', 'listHousekeepingType', {});
                            return;
                        }
                        vc.toast(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            },
            _listAShopMenuShops: function () {
                let param = {
                    params: {
                        page: 1,
                        row: 100
                    }
                };
                //发送get请求
                vc.http.apiGet('/shop.queryShopsByAdmin',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.addAShopMenuInfo.shops = _json.data;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },

            clearAddAShopMenuInfo: function () {
                $that.addAShopMenuInfo = {
                    hktId: '',
                    hktName: '',
                    hktIcon: '',
                    hktDesc: '',
                    label: '',
                    seq: '',
                    url: '',
                    skipType: 'S',
                    isShow: '',
                    typeCd: '2002',
                    shopId: '',
                    shops:[],
                };
                vc.emit("addAShopMenu", 'uploadImage', 'clearImage', {})
            }
        }
    });

})(window.vc);